/*
 * UserTest.java
 * Author: Thach Nguyen
 * Version 5/21/2011 tests all starter code
 * Version 5/25/2011 Modified tests to reflect new format
 * Version 6/01/2011 Added tests for maxCredits & addUserType().
 */
package user;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.HashSet;
import java.util.Set;

import org.junit.Before;
import org.junit.Test;

import data.ClassDays;
import data.ClassPreference;
import data.TimeSlot;

/**
 * Tests the methods of the User class.
 * 
 * @author Warran
 * @version 6/01/2011
 */
public class UserTest {
	
	private User myTestUser;
	
	@Before
	public void init() {
		myTestUser = new User(0, "Thach", new UserType[]{});
	}
	
	/**
	 * Tests getUserID() as well as the constructor.
	 */
	@Test
	public void testGetUserID() {
		assertEquals(0, myTestUser.getUserID());
	}
	
	@Test
	public void testGetName() {
		assertEquals("Thach", myTestUser.getName());
	}
	
	@Test (expected = NullPointerException.class)
	public void testGetClassesWrongUserType() {
		myTestUser.getClasses(UserType.TEACHER);
	}
	
	@Test (expected = NullPointerException.class)
	public void testGetTimesWrongUserType() {
		myTestUser.getTimes(UserType.STUDENT);
	}
	
	@Test
	public void testAddUserType() {
		myTestUser.addUserType(UserType.STUDENT);
		assertTrue(myTestUser.getUserType().contains(UserType.STUDENT)); //Tests that the UserType was added
		assertEquals(0, myTestUser.getClasses(UserType.STUDENT).size()); //Tests that the class preference list was created
		assertEquals(0, myTestUser.getTimes(UserType.STUDENT).size()); //Tests that the time preference list was created.
	}
	
	@Test (expected = NullPointerException.class)
	public void testAddClassWrongUserType() {
		ClassPreference test = new ClassPreference("TCSS322", "Discrete Structures II", 'A', 5);
		myTestUser.addClass(test, UserType.STUDENT);
	}
	
	@Test (expected = NullPointerException.class)
	public void testAddTimeWrongUserType() {
		TimeSlot test = new TimeSlot(null, 0, 0);
		myTestUser.addTime(test, UserType.STUDENT);
	}
	
	@Test
	public void testAddClassCorrectUserType() {
		ClassPreference test = new ClassPreference("TCSS322", "Discrete Structures II", 'A', 5);
		myTestUser.addUserType(UserType.STUDENT);
		myTestUser.addClass(test, UserType.STUDENT);
		assertTrue(myTestUser.getClasses(UserType.STUDENT).contains(test));
	}
	
	@Test
	public void testAddTimeCorrectUserType() {
		Set<ClassDays> temp = new HashSet<ClassDays>();
		temp.add(ClassDays.MONDAY);
		TimeSlot test = new TimeSlot(temp, 0, 0);
		myTestUser.addUserType(UserType.STUDENT);
		myTestUser.addTime(test, UserType.STUDENT);
		assertTrue(myTestUser.getTimes(UserType.STUDENT).contains(test));
	}
	
	@Test
	public void testEquals() {
		User test = new User(0, "Phill", UserType.ADVISER);
		assertEquals(test, myTestUser); //as long as they have the same UID.
	}
	
	@Test
	public void testSetMaxCredits() {
		myTestUser.setMyMaxCredits(10);
		assertEquals(10, myTestUser.getMyMaxCredits());
	}

}
